package com.deeper.customview.ui.c7.demo.c07d02;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.deeper.customview.BaseFragment;
import com.deeper.customview.R;

public class Chapter07Demo02Fragment extends BaseFragment {


    private LinearLayout linearLayout;
    private Button scrollby;
    private Button scrollto;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_chapter07_demo02, container, false);
        linearLayout = root.findViewById(R.id.linearlayout);
        scrollby = root.findViewById(R.id.scrollby2);
        scrollby.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                linearLayout.scrollBy(-5, 0);
            }
        });
        scrollto = root.findViewById(R.id.scrollto2);
        scrollto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int x = linearLayout.getScrollX();
                int y = linearLayout.getScrollY();
                linearLayout.scrollTo(x - 5, 0);
            }
        });
        return root;
    }
}
